import pageination from '../../components/pageination/pageination.vue'
export default {
	data() {
			return {
				userData: [],
				//数据
				total: 0, //总条数
				page: 1, //当前页
				size: 10, //每页显示条数
				fatherIndex: 0, //一级菜单index
			}
		},
		components: {
			pageination
		},
		created() { //调用方法
			let that = this;

		},
		mounted() {},
		updated:function(){
			if(this.getParamValue("fatherIndex")){
				this.fatherIndex=this.getParamValue("fatherIndex");
			}
		},
		methods: { //写函数方法

			getData: function() {
				let that = this;
				that.$post(
						that.urls.findAllUser, {
							"pageNum": that.page,
							"pageSize": that.size
						}
					)
					.then(function(res) {
						if (res.success) {
							that.userData = res.pageInfo.list;
							that.page = res.pageInfo.pageNum;
							that.total = res.pageInfo.total;

						}
					})
			},
			//页码切换执行方法
			pageFn: function(val, pid) {
				this.page = parseInt(val);
				this.getData();
				//此处调列表数据接口
				//	this.searchTodo(pid); //查询新闻
			},
			/**返回子组件用户选择的一页显示条数**/
			obtainChild: function(data) {
				this.row = data;
			},
			//删除

			deleteUser: function(id, roleName) {
				let that = this;

				layer.confirm('你确定要删除吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					if (id != null) {
						that.$post(
								that.urls.removeUser, {
									"id": id
								}
							)
							.then(function(res) {
								let msg = "";
								if (res.success) {
									msg = '删除用户成功！';
									that.getData();

									/*        if(roleName && roleName === '学生'){
									          that.$post(  // 删除,学生
									            that.urls.removeStudent,
									            {"userId": id}
									          )
									            .then(function(res) {
									              if(res.success) {

									              }
									            })
									        }else if(roleName && roleName === '专家'){
									          that.$post(  // 删除专家,
									            that.urls.delExpert,
									            {"id": id}
									          )
									            .then(function(res) {
									              if(res.success) {

									              }
									            })
									        }*/

								} else {
									msg = '删除用户失败！';
								}
								layer.msg(msg, {
									time: 3000, //3s后自动关闭
								});
							})
					}
				});

			},
			toDateStr(timestamp) {
				let time = new Date(timestamp) // 先将时间戳转为Date对象，然后才能使用Date的方法
				let year = time.getFullYear(),
					month = time.getMonth() + 1, // 月份是从0开始的
					day = time.getDate();
				//  hour = time.getHours(),
				//  minute = time.getMinutes(),
				//  second = time.getSeconds();
				//  return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
				return year + '-' + month + '-' + day;
			},
			searchUser: function() {
				let that = this;
				let value = $('#searchUserVal').val();
				that.$post(
						that.urls.findAllUser, {
							"pageNum": that.page,
							"pageSize": that.size,
							userName: value
								//	"userPhoneNumber": parseInt(value),
						}
					)
					.then(function(res) {
						if (res.success) {
							that.userData = res.pageInfo.list;
							that.page = res.pageInfo.pageNum;
							that.total = res.pageInfo.total;

						}
					})

			},
			//编辑用户
			editorUser: function(id) {
				if (id != null && id != "") {
					this.set("addUserid", id);
					this.$router.push({
						path: "addUser?fatherIndex="+this.fatherIndex,
					})
				} else {
					this.remove("addUserid", "");
					this.$router.push({
						path: "/addUser?fatherIndex="+this.fatherIndex,
					})
				}
				//			console.log('upd' + id)
				//			this.$router.push({
				//				path: "addUser/" + id,
				//				params: {
				//					id: id
				//				}
				//			})

			},
			//查看用户
			viewUser: function(id) {
				//			console.log('view' + id)
				this.set("ToViewUserid", id);
				this.$router.push({
					path: "ToViewUser?fatherIndex="+this.fatherIndex,
					//				params: {
					//					id: id
					//				}
				})
			},

			// 修改角色状态
			editStatus: function(id, sta) {
				let that = this;
				that.$post(
						that.urls.editUser, {
							"id": id,
							"userAccountStatus": sta
						}
					)
					.then(function(res) {
						if (res.success) {
							layer.msg('修改用户状态成功!', {
								time: 3000, //3s后自动关闭
							});
							that.getData();
						} else {
							layer.msg('修改用户状态失败!', {
								time: 3000, //3s后自动关闭
							});
						}
					})
			}

		}
}